package com.common.sdk.net.connect.fresco;

import android.net.Uri;

import com.facebook.cache.common.CacheKey;
import com.facebook.common.util.HashCodeUtil;

/**
 * Created by sangchengjiang on 16/8/10.
 */
public class PostprocessorCacheKey implements CacheKey {

    private int width;
    private int height;
    private Uri uri;

    public PostprocessorCacheKey(int width, int height, Uri uri) {
        this.width = width;
        this.height = height;
        this.uri = uri;
    }

    @Override
    public boolean containsUri(Uri uri) {
        if (uri == null) {
            return false;
        } else if (uri.equals(this.uri)) {
            return true;
        }
        return false;
    }

    @Override
    public String getUriString() {
        return uri.toString();
    }

    @Override
    public int hashCode() {
        return HashCodeUtil.hashCode(uri, width, height);
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        if (o instanceof PostprocessorCacheKey) {
            PostprocessorCacheKey other = (PostprocessorCacheKey) o;
            if (other.uri == null) {
                return false;
            }
            if (other.uri.equals(uri) && other.width == width && other.height == height) {
                return true;
            }
        }
        return super.equals(o);
    }
}
